/***************************************************************************
 *   Copyright (C) 2010 by programmeboy                                    *
 *   programmeboy@gmail.com                                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.                                        *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * 
 ***************************************************************************/

#ifndef __IDT_H__
#define __IDT_H__

#define MAX_IDT_ENTRIES		0xFF
#define NT_INT_TIMER        0x30

#define MAKELONG(a, b) ((ULONG)(((USHORT)(((ULONG_PTR)(a)) & 0xffff)) | ((ULONG)((USHORT)(((ULONG_PTR)(b)) & 0xffff))) << 16))

///////////////////////////////////////////////////
// IDT structures
///////////////////////////////////////////////////
#pragma pack(1)

//
// entry in the IDT, this is sometimes called
// an "interrupt gate"
//

typedef struct _IDTENTRY
{
	USHORT LowOffset;
	USHORT Selector;
	UCHAR unused_lo;
	UCHAR SegmentType:4;	//0x0E is an interrupt gate
	UCHAR SegmentFlag:1;
	UCHAR DPL:2;			// descriptor privilege level 
	UCHAR P:1;				// present
	USHORT HiOffset;
}IDTENTRY, *PIDTENTRY;

//
// sidt returns idt in this format
//

typedef struct _IDTINFO
{
	USHORT IDTLimit;
	USHORT LowIDTbase;
	USHORT HiIDTbase;
}IDTINFO, *PIDTINFO;

#pragma pack()

typedef struct _IDT_OUT_ENTRY
{
	USHORT Selector;
	ULONG  SegmentAddr;
	ULONG Routine;
	
}IDT_OUT_ENTRY, *PIDT_OUT_ENTRY;

ULONG
QueryIDTEntryCounts();
NTSTATUS
QueryIDTEntrys(
	OUT PVOID Buffer,
	IN ULONG InputLength,
	OUT PULONG OutputLength
);

#endif